package com.adamjwh.pratice.offer;

import com.adamjwh.tools.ListNode;

/**
 * 输入一个链表，反转链表后，输出新链表的表头。
 */
public class ReverseTheList {

    public ListNode ReverseList(ListNode head) {
        ListNode pHead = null;
        ListNode pNode = head;
        ListNode pPre = null;

        while(pNode != null) {
            ListNode pNext = pNode.next;

            if(pNext == null) {
                pHead = pNode;
            }
            pNode.next = pPre;
            pPre = pNode;
            pNode = pNext;
        }

        return pHead;
    }

}
